/*
 * The National Parks Database Project
 * Group: Tyler Simrell, Vladmir Dudnic, Michael Jagielo
 * Maintenance.java
 */
package database;

import java.text.DecimalFormat;
import java.util.ArrayList;

/**
 * This class has a static method that creates the queries necessary for populating
 * the tables in the database. It is expandable to allow for more trail names, vista points
 * and park names.
 * @author Tyler Simrell
 * @version 5/24/13
 *
 */
public class TableGenerator 
{
	//Arbitrary values for determining difficulty of trail
	private static final double HARD = 70 * 8;
	private static final double MEDIUM = 50 * 5;
	
	private static String[] trailNames = {"Slippery Rock", "Eagle Crest", "Tumble Creek", "Silver River", "Rushing Wind", 
			"Willow Loop", "Rattlesnake Creek", "Gypsy Ridge", "Crystal Falls", "Perkins", "Glacier View", "Goat Lake",
			"Tohickon Creek", "Squawk Meadow", "Amber Canyon", "Mule Hitch", "Skunk Hop", "Possum Skate", "Pebble Path", 
			"Shale Path"};

	private static String[] parkNames = {"Mossy Mountain", "Mt. Rainier", "Towhee Wilderness", "Spangler Backcountry", "Red Valley", 
			"Pioneer Forest", "Scapegoat Wilderness", "Forgotten Wastelands", "Masterson Valley", "Eagle Rock"};
	
	private static String[] vistaNames = {"Dogwood View", "Patterson Lake Viewpoint", "Grandview Point", "Shifty Ridge Lookout",
			"Goat Slip Viewpoint", "Birchview Vista", "Boulder Ridge Vista", "Black Mountain Viewpoint", 
			"WhiteCap Lookout", "Silvercrest ViewPoint"};
	
	/**
	 * This method generates an arraylist to populate the table.
	 * @return An arraylist of all of the tuples necessary to insert into a database.
	 */
	public static ArrayList<String> generateInsertQueries()
	{
		ArrayList<String> insertQueries = new ArrayList<String>();
		String firstKeywordsTI = "INSERT INTO trail_inventory (trail_name, park_name, slope, terrain, vista, " +
				"length, difficulty)";
		String secondKeywords = "VALUES (";
		DecimalFormat formatter = new DecimalFormat("0.00"); // A class used to make doubles formatted for textual viewing. 
		
		
		for(int i = 0; i < trailNames.length; i++)
		{
			String tempParkName = parkNames[(int)(Math.random() * parkNames.length)];
			double tempSlope = (Math.random() * 100); // Slope can go from 0 to 100 feet
			String tempTerrain = null;
			if(Math.random() > .5)
			{
				tempTerrain = "Meadow";
			}
			else
			{
				tempTerrain = "Forest";
			}
			String tempVista = vistaNames[(int)(Math.random() * parkNames.length)];
			double tempLength = (Math.random() * 10); // Length can go from 0 to 10 miles
			String tempDifficulty = null;
			double difficultyRating = tempSlope * tempLength; 
			if(difficultyRating > HARD)
			{
				tempDifficulty = "Hard";
			}
			else if(difficultyRating > MEDIUM && difficultyRating < HARD)
			{
				tempDifficulty = "Medium";
			}
			else
			{
				tempDifficulty = "Easy";
			}
			
			StringBuilder tuple = new StringBuilder(firstKeywordsTI);
			tuple.append("\n");
			tuple.append(secondKeywords);
			tuple.append(tempParkName);
			tuple.append(", ");
			tuple.append(formatter.format(tempSlope));
			tuple.append(", ");
			tuple.append(tempTerrain);
			tuple.append(", ");
			tuple.append(tempVista);
			tuple.append(", ");
			tuple.append(formatter.format(tempLength));
			tuple.append(", ");
			tuple.append(tempDifficulty);
			tuple.append(")");
			
			insertQueries.add(tuple.toString());
		}
		
		String firstKeywordsMU = "INSERT INTO maint_user (trail_name, melt_out, wash_out, open)";
		
		for(int i = 0; i < trailNames.length; i++)
		{
			String tempParkName = trailNames[i];
			double tempMeltOut = Math.random() * 100;
			double tempWashOut = Math.random() * 100;
			String tempOpenStatus = null;
			if(tempMeltOut > 60 || tempWashOut > 60)
			{
				tempOpenStatus = "Closed";
			}
			else
			{
				tempOpenStatus = "Open";
			}
			
			StringBuilder tuple = new StringBuilder(firstKeywordsMU);
			tuple.append("\n");
			tuple.append(secondKeywords);
			tuple.append(tempParkName);
			tuple.append(", ");
			tuple.append(formatter.format(tempMeltOut));
			tuple.append(", ");
			tuple.append(formatter.format(tempWashOut));
			tuple.append(", ");
			tuple.append(tempOpenStatus);
			tuple.append(")");
			
			insertQueries.add(tuple.toString());
		}
		
		
		return insertQueries;
	}
	
//	public static void main(String[] args)
//	{
//		ArrayList<String> table = TableGenerator.generateInsertQueries();
//		for(String tuple : table)
//		{
//			System.out.println(tuple);
//		}
//	}
}
